//
//  filterHotelView.m
//  PassFeed
//
//  Created by passfeediOS on 16/8/26.
//
//

#import "LHButtonView.h"

static NSUInteger const btnCount=4;

@implementation LHButtonView

-(instancetype)initWithFrame:(CGRect)frame AndTitleArray:(NSArray*)titleArr AndImageArray:(NSArray*)imageArr
{
    self=[super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[UIColor whiteColor];
//       
//        NSArray *images = [NSArray arrayWithObjects:imageArr, nil];
//        NSArray *titles = [NSArray arrayWithObjects:titleArr, nil];
        // 计算btn的宽度
        CGFloat width = ([UIScreen mainScreen].bounds.size.width)/btnCount;
        for (NSUInteger idx = 0; idx < btnCount; idx ++) {
            // X 坐标
            NSUInteger pointX = idx % btnCount;
            // Y 坐标
            // NSUInteger pointY = idx / 4;
            self.cellBtn = [LHButton buttonWithType:UIButtonTypeCustom];
            _cellBtn.frame = CGRectMake(pointX * width,0, width, 48);
            // 设置文字
            [_cellBtn setTitle:titleArr[idx] forState:UIControlStateNormal];
            [_cellBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            // 设置图片
            _cellBtn.tag=1000+idx;
            [_cellBtn setImage:[UIImage imageNamed:imageArr[idx]] forState:UIControlStateNormal];
            [_cellBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:_cellBtn];
        }
    }
    return  self;
}
- (void)btnAction:(LHButton *)cellBtn
{
    switch (cellBtn.tag) {
        case 1000:
        {

            if (self.locationBtnClickBlock) {
                self.locationBtnClickBlock();
            }
            else if ([_delegate respondsToSelector:@selector(locationBtnDidClick:)]){
                [_delegate locationBtnDidClick:cellBtn];
            }
        }
            break;
            
        case 1001:
        {
            if (self.filterBtnBlock) {
                self.filterBtnBlock();
            }

           else if ([_delegate respondsToSelector:@selector(filterBtnDidClick:)]) {
                [_delegate filterBtnDidClick:cellBtn];
            }
        }
            break;
            
        case 1002:
        {
            if (self.currencyBtnBlock) {
                self.currencyBtnBlock();
            }

           else if ([_delegate respondsToSelector:@selector(currencyBtnDidClick:)]) {
                [_delegate currencyBtnDidClick:cellBtn];
            }
        }
            break;
            
        case 1003:
        {
            if (self.sortBtnBlock) {
                self.sortBtnBlock();
            }

           else if ([_delegate respondsToSelector:@selector(sortBtnDidClick:)]) {
                [_delegate sortBtnDidClick:cellBtn];
            }
        }
            break;
            
        default:
            break;
    }

}

@end

